.PHONY: all clean

all: ../../target/mgr_mod_${MOD_NAME}

-include Makefrag.mk

SRCFILES?= $(shell ${FIND} . -iname "*.c" -or -iname "*.S" | sed -e 's!\./!!g')
OBJFILES:= $(addprefix ../../target/mgr_mod_${MOD_NAME}_,\
		     $(addsuffix .o,$(shell echo ${SRCFILES} | sed -e 's!_!_1!g' -e 's!/!_2!g')))
DEPFILES:= $(OBJFILES:.o=.d)

-include $(DEPFILES)

../../target/mgr_mod_${MOD_NAME}_%.S.d: 
	@${ECHO} DEP $(shell echo $*|sed -e 's!_1!_!g' -e 's!_2!/!g').S
	${V}${TARGET_CC} -D__ASSEMBLY__ -MM $(CCFLAGS) $(shell echo $* | sed -e 's!_1!_!g' -e 's!_2!/!g').S -MT $(@:.d=.o) > $@
	${V}echo "$(@:.d=.o): $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').S" >> $@

../../target/mgr_mod_${MOD_NAME}_%.c.d: 
	@${ECHO} DEP $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').c
	${V}${TARGET_CC} -MM $(CCFLAGS) $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').c -MT $(@:.d=.o) > $@
	${V}echo "$(@:.d=.o): $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').c" >> $@

../../target/mgr_mod_${MOD_NAME}_%.S.o: ../../target/mgr_mod_${MOD_NAME}_%.S.d
	@${ECHO} CC $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').S
	${V}${TARGET_CC} -D__ASSEMBLY__ $(CCFLAGS) $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').S -c -o $@

../../target/mgr_mod_${MOD_NAME}_%.c.o: ../../target/mgr_mod_${MOD_NAME}_%.c.d
	@${ECHO} CC $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').c
	${V}${TARGET_CC} $(CCFLAGS) $(shell echo $*| sed -e 's!_1!_!g' -e 's!_2!/!g').c -c -o $@

../../target/mgr_mod_${MOD_NAME}: ${OBJFILES}
	echo ${SRCFILES}
	@${ECHO} LD $@
	${V}${TARGET_LD} -N -r -T ../mgr_mod.ld -o $@ ${OBJFILES}
